﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FarseerPhysics.Dynamics;
using Microsoft.Xna.Framework;
using MapLibrary;
using Animation;
using FarseerPhysics;

namespace AI
{
    class GermBot : Bot
    {
        public enum State{
            WALKING_LEFT,
            WALKING_RIGHT,
            IDLE_LEFT,
            IDLE_RIGHT
        }

        private State currentState;

        public GermBot()
        {
            
        }

        public override void Init(GameWorld world, Microsoft.Xna.Framework.Content.ContentManager cm)
        {
            currentState = State.WALKING_LEFT;
            Owner.Type.CurrentState = "Walking Left";
        }

        public void ChangeDirection()
        {
            if (currentState == State.WALKING_LEFT)
            {
                currentState = State.WALKING_RIGHT;
                Owner.Type.CurrentState = "Walking Right";
            }
            else
            {
                currentState = State.WALKING_LEFT;
                Owner.Type.CurrentState = "Walking Left";
            }
            Owner.Body.LinearVelocity = new Vector2(0, 0);
        }

        public override void Update(MapLibrary.Level level, FarseerPhysics.Dynamics.World world)
        {
            if (currentState == State.WALKING_LEFT)
            {
                if (!this.NearLedgeLeft(1.0f))
                {
                    Owner.Body.ApplyLinearImpulse(new Vector2(-0.1f, 0));
                }
                else
                {
                    if (DistanceFromFloor() > .05) 
                        ChangeDirection();
                }
            }
            else if (currentState == State.WALKING_RIGHT)
            {
                if (!this.NearLedgeRight(1.0f))
                {
                    Owner.Body.ApplyLinearImpulse(new Vector2(0.1f, 0));
                }
                else
                {
                    if(DistanceFromFloor() > .05)
                        ChangeDirection();
                }
            }
        }

    }
}
